<?php
	//echo date("Y年-m月-d日 H:i:s",time());
	
	ini_set('display_errors',1);
	header('Content-Type: text/html; charset=utf-8');
	
	
	$lat   = (float)$_REQUEST['lat'];
	$long  = (float)$_REQUEST['long'];	
	
	//var_dump($lat,$long);die;
	
	if (!$lat || !$long) {
		echo "return no address";
		return;
	}
	
	$near = array($lat,$long);
	
	$m = new Mongo("localhost:27017", array("persist" => "x"));
	$db = $m->gshow;
	$collection = $db->geos;
	
	// find everything in the collection
	$cursor = $collection->find(
		 array(
			"loc"=>array( '$near' => $near )
		 )
	)->limit(10);
	
	//$cursor = $db->command(array('geoNear'=>'geos','near'=>array(31,121),'num'=>9));
	
	//$cursor = $collection->find(Array('loc' => Array('$near' => array(31,121) )));	
	//var_dump($cursor). "\n";
	// iterate through the results
	$returns = array();
	
	foreach ($cursor as $obj) {
	    //var_dump($obj). "\n";
	    $obj['yyyy'] = date("Y年-m月-d日 H:i:s",$obj['time']);
	    $returns[] = $obj;
	}
	
		
	echo json_encode($returns);
